/*
 * @Descripttion: 
 * @Author: xiaodong
 * @Date: 2021-01-25 19:46:05
 * @LastEditTime: 2021-01-25 20:15:05
 * @FilePath: \cloud-monitor-server\src\routes\api\pv\index.js
 */
import RouterConfigBuilder from '~/src/library/utils/modules/router_config_builder'
import moment from 'moment'
import _ from 'lodash'
import MPv from '~/src/model/parse/pv_record'
import API_RES from '~/src/constants/api_res'

const getPVCount = RouterConfigBuilder.routerConfigBuilder('/api/dashboard/pv', RouterConfigBuilder.METHOD_TYPE_GET, async (req, res) => {
  const projectId = _.get(req, ['fee', 'project', 'projectId'], 1)
  let st = parseInt(_.get(req, ['query', 'st'], moment().unix() * 1000))
  let et = parseInt(_.get(req, ['query', 'et'], moment().unix() * 1000))

  if (_.isInteger(st) === false || _.isInteger(et) === false) {
    res.send(API_RES.showError('st或et格式不对'))
    return
  }
  // st = st / 1000
  // et = et / 1000
  const pvReord = await MPv.getPVInRange(projectId, st, et)
  res.send(API_RES.showResult(pvReord))
})

export default {
  ...getPVCount
}
